package com.starmark.message.queue.producer.kafka.service.impl;

import com.starmark.message.queue.producer.api.dto.MessageQueueDto;
import com.starmark.message.queue.producer.api.service.IMessageQueueProducerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * redis 消息队列
 *
 * @author starmark
 * @date 2020/5/1  上午10:41
 */
@Service
public class MessageQueueKafkaProducerServiceImpl implements IMessageQueueProducerService {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;
    @Override
    public boolean produceMessage(MessageQueueDto messageQueueDto) {
        kafkaTemplate.send(messageQueueDto.getTopic(),messageQueueDto.getMessage());
        return true;
    }

    @Override
    public boolean support(String producerType) {
        return Objects.equals(producerType, "kafka");
    }
}
